package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup

//定义chan
var tasklist = make(chan int)

//生产者
func creat1(i int) {
	defer wg.Done()
	fmt.Println("存入", i)
	//调用存
	tasklist <- i
}

//销费者
func work() {
	defer wg.Done()
	mes := <-tasklist
	fmt.Println("取也的值为", mes)
}

func main() {
	for i := 0; i < 3; i++ {
		wg.Add(1)
		go creat1(i)
	}

	for i := 0; i < 3; i++ {
		wg.Add(1)
		go work()
	}
	wg.Wait()
	// time.Sleep(time.Second * 13)
}
